<?php


use Drupal\wx_mini_tmplmsg\Entity\WxMiniTmplmsgIds;

function _wx_mini_tmplmsg_services_submit_id(int $type, string $id_string) {
  try {
    global $user;
    $o = new WxMiniTmplmsgIds();
    $o->type = $type;
    $o->uid = $user->uid;
    $o->id_string = $id_string;
    $o->validity = (REQUEST_TIME + (7 * 24 * 3600) - 3600);
    switch ($type) {
      case 0:
        {
          $o->count = 1;
          break;
        }
      case 1:
        {
          $o->count = 3;
          break;
        }
    }
    $o->save();
    return [
      'code' => 0,
      'msg' => 'ok',
    ];
  } catch (Exception $exception) {
    watchdog_exception(__FUNCTION__, $exception);
    return [
      'code' => 1,
      'msg' => '系统错误',
    ];
  }
}
